package in.srain.cube.views.loadmore;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;

import in.srain.cube.views.GridViewWithHeaderAndFooter;

/**
 * @author huqs
 */
public class LoadMoreRecyclerViewContainer extends LoadMoreContainerBase {
    private RecyclerView mRecyclerView;
    private RecyclerAdapterWithHF mRecyclerAdapter;
    public LoadMoreRecyclerViewContainer(Context context) {
        super(context);
    }

    public LoadMoreRecyclerViewContainer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    protected void addFooterView(View view) {
//        System.out.println("添加头部View-------->"+view);
    }

    @Override
    protected void removeFooterView(View view) {
        if ( mRecyclerView.getAdapter() instanceof  RecyclerAdapterWithHF){
            mRecyclerAdapter= (RecyclerAdapterWithHF) mRecyclerView.getAdapter();
            mRecyclerAdapter.removeFooter(view);

        }
    }
    public void initFooterView(){
        if ( mRecyclerView.getAdapter() instanceof  RecyclerAdapterWithHF){
            mRecyclerAdapter= (RecyclerAdapterWithHF) mRecyclerView.getAdapter();
            mRecyclerAdapter.addFooter(mFooterView);
            mFooterView.setVisibility(GONE);
        }
    }

    @Override
    protected RecyclerView retrieveAbsListView() {
        View view = getChildAt(0);
        mRecyclerView = (RecyclerView) view;
        return mRecyclerView;
    }
}